﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Maniax.HoldEm
{
    public class Deck
    {
        public Deck()
        {
            Reset();
        }

        public bool IsEmpty
        {
            get
            {
                return cards_.Count == 0;
            }
        }

        public Card DrawCard()
        {
            Card card = cards_[0];
            cards_.RemoveAt(0);

            return card;
        }

        public Card DrawRandomCard()
        {
            Random randomIndex_ = new Random();

            int index = randomIndex_.Next(cards_.Count);

            Card card = cards_[index];
            cards_.RemoveAt(index);

            return card;
        }

        public void Reset()
        {
            cards_ = new List<Card>();

            foreach(Card.SuitType suit in Enum.GetValues(typeof(Card.SuitType)))
            {
                foreach(Card.RankType rank in Enum.GetValues(typeof(Card.RankType)))
                {
                    cards_.Add(new Card(suit, rank));
                }
            }
        }

        public void Shuffle()
        {

            for (int i = 0; i < 8; i++)
            {
                List<Card> shuffledCards = new List<Card>();

                while (cards_.Count > 0)
                {
                    shuffledCards.Add(DrawRandomCard());
                }

                cards_ = shuffledCards;
            }
               
        }

       

       
        private List<Card> cards_;
    }
}
